function w = mLeastSquares(c1, c2, tMax)

mu = 1;

s1 = size(c1);
s2 = size(c2);

y1 = 0;
y1(1:s1(1)) = 1;
Yc1 = horzcat(y1', c1);

y2 = 0;
y2(1:s2(1)) = 1;
Yc2 = horzcat(y2', c2);
Yc2 = Yc2*-1;

sYc1 = size(Yc1);
sYc2 = size(Yc2);

b = 0;
b(1:length(Yc1) + length(Yc2)) = 1;
b = b';

Y = vertcat(Yc1, Yc2);
a = 0;
a = Y\b;

dA(1:sYc1(2)) = 0.00001;



t=0;
stop = 0;
h = waitbar(0,'Calcul du percptron...');
set(h,'Name','Perceptron');
while(stop==0)
   
    e = Y*a - b;
    b = b+mu*(e+abs(e))/2;
    
    tmp = a;
    a = Y\b;
    

    t = t+1;
    mu = 1/log(t+1);
    
    if(t>tMax || norm(a-tmp)<0.001)
        stop = 1;
    end
    waitbar(t/tMax);
end
close(h);

if (stop==1 && t<tMax)
    % fin calcul  de a
    w = a
    min1 = min(min(c1), min(c2));
    max1 = max(max(c1), max(c2));
    axis([min1(1), max1(1), min1(2), max1(2), min1(3), max1(3)]);
    v = axis;


    figure;
    hold on
    traceSurface(a, v(1), v(2), v(3), v(4));
    %pline(a(2:end),30);
    plot3(c1(:,1), c1(:,2), c1(:,3), 'g.');
    plot3(c2(:,1), c2(:,2), c2(:,3), 'r.');
end


end